﻿using Architecture.API.Application.TraceabilityCommand.PictureCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.PictureService;

namespace Architecture.API.Application.TraceabilityCommandHandler.PictureCommandHandler
{
    /// <summary>
    /// 图片信息更新命令处理器
    /// </summary>
    public class PictureUpdateCommandHandler : IRequestHandler<PictureUpdateCommand, int>
    {
        /// <summary>
        /// 图片服务
        /// </summary>
        protected readonly IPictureService pictureService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pictureService">图片服务</param>
        public PictureUpdateCommandHandler(IPictureService pictureService)
        {
            this.pictureService = pictureService;
        }

        public async Task<int> Handle(PictureUpdateCommand request, CancellationToken cancellationToken)
        {
            return await pictureService.UpdatePicture(new Pictures() { PictureId = request.PictureId, PictureName = request.PictureName, ProductionBatch = request.ProductionBatch, EnterpriseId = request.EnterpriseId, TraceabilityId = request.TraceabilityId, Slaughter = request.Slaughter, DeepProcessingId = request.DeepProcessingId,RawMaterialId=request.RawMaterialId,AuxiliaryMaterialsId=request.AuxiliaryMaterialsId,AdditiveId=request.AdditiveId,PackagingMaterialsId=request.PackagingMaterialsId, UpdatedBy=request.UpdatedBy,UpdatedDate=DateTime.Now });
        }
    }
}
